home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / xml4j.jar / com / ibm / xml / xpointer / RelTerm.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-08-30  |  3.2 KB  |  238 lines

  1. package com.ibm.xml.xpointer;
  2.  
  3. import com.ibm.xml.parser.TXElement;
  4. import java.io.Serializable;
  5. import java.util.Enumeration;
  6. import java.util.Vector;
  7. import org.w3c.dom.Attr;
  8. import org.w3c.dom.CDATASection;
  9. import org.w3c.dom.Comment;
  10. import org.w3c.dom.Element;
  11. import org.w3c.dom.Node;
  12. import org.w3c.dom.ProcessingInstruction;
  13. import org.w3c.dom.Text;
  14.  
  15. public class RelTerm implements OtherTerm, Serializable {
  16.    static final long serialVersionUID = -742339128434233398L;
  17.    int keywordType;
  18.    boolean isAll;
  19.    int instance;
  20.    int nodeType;
  21.    String elementName;
  22.    Vector attributes;
  23.  
  24.    public RelTerm(int var1, boolean var2, int var3, int var4, String var5, Vector var6) {
  25.       this.keywordType = -1;
  26.       this.isAll = false;
  27.       this.instance = -1;
  28.       this.nodeType = -1;
  29.       this.keywordType = var1;
  30.       this.isAll = var2;
  31.       this.instance = var3;
  32.       this.nodeType = var4;
  33.       this.elementName = var5;
  34.       this.attributes = var6;
  35.    }
  36.  
  37.    public RelTerm(int var1, int var2, int var3) {
  38.       this(var1, false, var2, var3, (String)null, new Vector());
  39.    }
  40.  
  41.    public RelTerm(int var1, boolean var2, int var3) {
  42.       this(var1, true, -1, var3, (String)null, new Vector());
  43.    }
  44.  
  45.    public RelTerm(int var1, int var2, String var3) {
  46.       this(var1, false, var2, 1, var3, new Vector());
  47.    }
  48.  
  49.    public RelTerm(int var1, String var2) {
  50.       this(var1, true, -1, 1, var2, new Vector());
  51.    }
  52.  
  53.    public RelTerm(int var1, int var2) {
  54.       this(var1, false, var2, -1, (String)null, new Vector());
  55.    }
  56.  
  57.    public RelTerm(int var1) {
  58.       this(var1, true, -1, -1, (String)null, new Vector());
  59.    }
  60.  
  61.    public int getType() {
  62.       return this.keywordType;
  63.    }
  64.  
  65.    public void setType(int var1) {
  66.       this.keywordType = var1;
  67.    }
  68.  
  69.    public String getTypeName() {
  70.       return this.keywordType == -1 ? null : XPointer.literals[this.keywordType];
  71.    }
  72.  
  73.    public boolean isAll() {
  74.       return this.isAll;
  75.    }
  76.  
  77.    public int getInstance() {
  78.       return this.instance;
  79.    }
  80.  
  81.    public int getNodeType() {
  82.       return this.nodeType;
  83.    }
  84.  
  85.    public String getElementName() {
  86.       return this.elementName;
  87.    }
  88.  
  89.    public Vector getAttributesVector() {
  90.       return this.attributes;
  91.    }
  92.  
  93.    public String toString() {
  94.       StringBuffer var1 = new StringBuffer(48);
  95.       if (this.keywordType != -1) {
  96.          var1.append(XPointer.literals[this.keywordType]);
  97.       }
  98.  
  99.       var1.append("(");
  100.       if (this.isAll) {
  101.          var1.append("all");
  102.       } else {
  103.          var1.append(this.instance);
  104.       }
  105.  
  106.       if (this.nodeType != 0) {
  107.          var1.append(",");
  108.          var1.append(this.nodeType == 1 ? this.elementName : XPointer.nodetypes[this.nodeType]);
  109.          Enumeration var2 = this.attributes.elements();
  110.  
  111.          while(var2.hasMoreElements()) {
  112.             var1.append(var2.nextElement().toString());
  113.          }
  114.       }
  115.  
  116.       var1.append(")");
  117.       return var1.toString();
  118.    }
  119.  
  120.    public boolean match(Node var1) {
  121.       boolean var2 = false;
  122.       switch (this.nodeType) {
  123.          case 0:
  124.          case 2:
  125.             var2 = var1 instanceof Element;
  126.             break;
  127.          case 1:
  128.             if (var1 instanceof Element) {
  129.                var2 = ((Element)var1).getTagName().equals(this.elementName);
  130.             }
  131.             break;
  132.          case 3:
  133.             var2 = var1 instanceof ProcessingInstruction;
  134.             break;
  135.          case 4:
  136.             var2 = var1 instanceof Comment;
  137.             break;
  138.          case 5:
  139.             var2 = var1 instanceof Text;
  140.             break;
  141.          case 6:
  142.             var2 = var1 instanceof CDATASection;
  143.             break;
  144.          case 7:
  145.             var2 = true;
  146.       }
  147.  
  148.       if (!var2) {
  149.          return var2;
  150.       } else if (this.attributes.size() == 0) {
  151.          return true;
  152.       } else if (!(var1 instanceof Element)) {
  153.          return false;
  154.       } else {
  155.          Element var3 = (Element)var1;
  156.          Enumeration var4 = this.attributes.elements();
  157.  
  158.          while(var4.hasMoreElements()) {
  159.             RelTermAttribute var5 = (RelTermAttribute)var4.nextElement();
  160.             String var6 = var5.getName();
  161.             if (var6.equals("*")) {
  162.                Enumeration var10 = ((TXElement)var3).attributeElements();
  163.                switch (var5.getValueType()) {
  164.                   case 0:
  165.                      if (var10.hasMoreElements()) {
  166.                         return false;
  167.                      }
  168.                      break;
  169.                   case 1:
  170.                      if (!var10.hasMoreElements()) {
  171.                         return false;
  172.                      }
  173.                      break;
  174.                   case 2:
  175.                      var2 = false;
  176.  
  177.                      while(var10.hasMoreElements()) {
  178.                         if (((Attr)var10.nextElement()).getValue().equalsIgnoreCase(var5.getValue())) {
  179.                            var2 = true;
  180.                            break;
  181.                         }
  182.                      }
  183.  
  184.                      if (!var2) {
  185.                         return false;
  186.                      }
  187.                      break;
  188.                   case 3:
  189.                      var2 = false;
  190.  
  191.                      while(var10.hasMoreElements()) {
  192.                         if (((Attr)var10.nextElement()).getValue().equals(var5.getValue())) {
  193.                            var2 = true;
  194.                            break;
  195.                         }
  196.                      }
  197.  
  198.                      if (!var2) {
  199.                         return false;
  200.                      }
  201.                }
  202.             } else {
  203.                Enumeration var7 = ((TXElement)var3).attributeElements();
  204.                Attr var8 = null;
  205.  
  206.                while(var7.hasMoreElements()) {
  207.                   Attr var9 = (Attr)var7.nextElement();
  208.                   if (var9.getName().equals(var6)) {
  209.                      var8 = var9;
  210.                      break;
  211.                   }
  212.                }
  213.  
  214.                switch (var5.getValueType()) {
  215.                   case 0:
  216.                      var2 = var8 == null;
  217.                      break;
  218.                   case 1:
  219.                      var2 = var8 != null;
  220.                      break;
  221.                   case 2:
  222.                      var2 = var8 != null && var8.getValue().equalsIgnoreCase(var5.getValue());
  223.                      break;
  224.                   case 3:
  225.                      var2 = var8 != null && var8.getValue().equals(var5.getValue());
  226.                }
  227.  
  228.                if (!var2) {
  229.                   return false;
  230.                }
  231.             }
  232.          }
  233.  
  234.          return var2;
  235.       }
  236.    }
  237. }
  238.